﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DomainModel;

namespace BL
{
  public static class BLTv
  {
    public static void InsertCustomer(Customer customer, ref List<string> errors)
    {
      if (customer == null)
      {
        errors.Add("Customer cannot be null");
        return;
      }

      if (customer.customer_id < 0)
      {
        errors.Add("Invalid customer ID");
        return;
      }
      if (customer.email.Length < 0)
      {
          errors.Add("Invalid customer Email");
      }
      if (customer.state.Length <= 0) 
      {
          errors.Add("Invalid state name"); 
      }
      if(customer.zip <= 4 )
      {
          errors.Add("Invalid zip code");
      
      }
       if( customer.webmaster > 2 || customer.webmaster < 0 )
        {

            errors.Add("Invalid mark for user state");
        }
       if (customer.blockuser > 1 || customer.blockuser < 0)
       {
           errors.Add("Invalid mard for block user");
       }
      if (errors.Count > 0)
        return;

      DALTv.InsertCustomer(customer, ref errors);
    }

    public static Customer GetCustomer(int id, ref List<string> errors)
    {
      if (id < 0)
      {
        errors.Add("Invalid customer ID");
        return null;
      }

      // anything else to validate?

      if (errors.Count > 0)
        return null;

      Customer customer = DALTv.GetCustomerDetails(id, ref errors);
      return customer;
    }

    public static void DeleteCustomer(int id, ref List<string> errors)
    {
      if (id < 0)
      {
        errors.Add("Invalid customer ID");
        return;
      }

      if (errors.Count > 0)
        return;

      DALTv.DeleteCustomer(id, ref errors);
    }

    public static List<Customer> GetCustomerList(ref List<string> errors)
    {
      return DALTv.GetCustomerNames(ref errors);
    }
  }
}
